﻿using System;
using System.Net;
using SCG.General;

namespace SCG.SolarVengeanceEngine
{
    //Represents an image defined in the Scenario
    public class ScenarioImage : SVObject
    {
        //constructor
        public ScenarioImage(SVGame game)
            : base(game)
        {
            Game.ScenarioImages.Add(this);
        }
        public ScenarioImage(SVGame game, string fileName, int x, int y, double opacity)
            : base(game)
        {
            ImageFileName = fileName;
            X = x;
            Y = y;
            Opacity = opacity;
            Game.ScenarioImages.Add(this);
        }

        //The file name of the image (under Images/Terrain folder)
        public string ImageFileName { get; set; }

        //The location of the image on the map
        public int X { get; set; }

        public int Y { get; set; }

        //Is the image visible?
        public bool IsVisible
        {
            get
            {
                return _visible;
            }
            set
            {
                _visible = true;
            }
        }

        //Opacity value for rendering
        public double Opacity
        {
            get
            {
                return _opacity;
            }
            set
            {
                _opacity = value;
            }
        }

        //the actual image
        public object Image { get; set; }

        //persistence
        public string Persist()
        {
            Tokenizer tok = new Tokenizer();
            tok.Tokenize(ImageFileName, X, Y, Opacity, IsVisible);
            return tok.Result;
        }
        public void Parse(string s)
        {
            Tokenizer tok = new Tokenizer(s);
            ImageFileName = tok.TokenString;
            X = tok.TokenInt;
            Y = tok.TokenInt;
            Opacity = tok.TokenDouble;
            IsVisible = tok.TokenBoolean;
        }

        //private members
        private bool _visible = true;
        private double _opacity = 1.0;
    }
}
